package com.wzy.facetextview.Utils;

import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.util.Log;

/**
 * 应用程序相关信息及手机相关信息获取的类
 */
public class AppUtils {

    private static final String TAG = "wang.AppUtils";
    private static AppUtils mAppUtils;
    private static final byte[] sLock = new byte[0];

    private static float mScreenDensity; // 屏幕密度
    private static int mScreenWidth;
    private static int mScreenHeight;

    private AppUtils() {
    }

    public static AppUtils getInstance(Context context) {

        synchronized (sLock) {
            if (mAppUtils == null) {
                mAppUtils = new AppUtils();
            }
        }
        init(context);
        return mAppUtils;
    }

    public static void init(Context context) {

        // 初始化手机尺寸信息
        Resources res = context.getResources();
        try {
            mScreenWidth = res.getDisplayMetrics().widthPixels;
            mScreenHeight = res.getDisplayMetrics().heightPixels;
            mScreenDensity = res.getDisplayMetrics().density;
        } catch (Exception e1) {
            Log.e(TAG, "get Resource is null or getDisplaymetrics is null");
            mScreenWidth = 720;
            mScreenHeight = 1080;
            mScreenDensity = 2;
        }

    }

    public int getScreenWidth() {

        return mScreenWidth;
    }

    public int getScreenHeight() {

        return mScreenHeight;
    }

    public float getScreenDensity() {

        return mScreenDensity;
    }

    public static int compare(int lhs, int rhs) {

        return lhs < rhs ? -1 : (lhs == rhs ? 0 : 1);
    }
}
